package com.ctrip.ec.biz.dao.order;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.order.OrderGoodsEntity;
import com.ctrip.ec.dal.DbAccess;
import com.ctrip.ec.dal.IdConvert;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderGoodsDao extends DaoBase<OrderGoodsEntity> {
    public OrderGoodsDao() {
        super(OrderGoodsEntity.class);
    }
    public OrderGoodsDao(DbAccess db) {
        super(OrderGoodsEntity.class,db);
    }

    public List<OrderGoodsEntity> listByOrderId(Long orderId) throws SQLException {
        String sql = "select * from " + this.getTableName() + " where order_id=?";
        List<OrderGoodsEntity> list = this.db.query(OrderGoodsEntity.class,sql,orderId);
        return list;
    }
    public List<OrderGoodsEntity> listByOrderId(List<Long> orderIds) throws SQLException {
        if(orderIds!= null && orderIds.size()>0) {
            String strOrderIds = IdConvert.join(orderIds);
            String sql = "select * from " + this.getTableName() + " where order_id in (" + strOrderIds + ")";
            List<OrderGoodsEntity> list = this.db.query(OrderGoodsEntity.class, sql);
            return list;
        }else {
            return new ArrayList<>();
        }
    }

}
